//
//  XXLeftViewController.m
//  XX
//
//  Created by lly on 15/5/25.
//  Copyright (c) 2015年 lly. All rights reserved.
//

#import "XXLeftViewController.h"
#import "XXCenterViewController.h"
#import "WZLeftFirstCell.h"
#import "WZLeftItemCell.h"
#import "XXDrawerViewController.h"
#import "XXOrderViewController.h"
@interface XXLeftViewController ()

@end

@implementation XXLeftViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        XXCenterViewController *vv = [[XXCenterViewController alloc] init];
        
        // Custom initialization
        self.navMainVC = [[XXNavigationController alloc] initWithRootViewController:vv];
        
        self.view.backgroundColor = [UIColor colorWithRed:0.965 green:0.965 blue:0.945 alpha:1.000];
        self.navMainVC.view.backgroundColor = [UIColor whiteColor];
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"个人中心";
    _configArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"MenuConfig" ofType:@"plist"]];
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame];
    self.tableView.backgroundColor = [UIColor colorWithRed:0.922 green:0.918 blue:0.949 alpha:1.000];
    self.tableView.delegate = self;
    self.tableView.bounces = NO;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    [self dataInit];
    
    //    [self buildFootView];
    // Do any additional setup after loading the view.
}

- (void)dataInit
{
    _currentIndex = 1;
}

- (void)closeDrawer
{
    [self.drawerViewController closeDrawerAnimated:YES completion:nil];
}

//- (void)buildFootView
//{
//    MZBottomView *bottom = [[MZBottomView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 90,265.0, 90)];
////    self.tableView.tableFooterView = bottom;
//    bottom.backgroundColor = [UIColor redColor];
//    [self.view addSubview:bottom];
//    __weak WZLeftViewController *weakself = self;
//    [bottom setTapIndexBlock:^(NSInteger index) {
//        if(!index)
//        {
//                /*    先关闭抽屉，然后推navigation    */
//            WZSettingController *setting = [[WZSettingController alloc] init];
//            [weakself closeDrawer];
//            [weakself.navMainVC pushViewController:setting animated:YES];
//        }
//        else if(index == 1)
//        {
//            WZAssViewController *assit = [[WZAssViewController alloc] init];
//            [weakself closeDrawer];
//            [weakself.navMainVC pushViewController:assit animated:YES];
//        }
//    }];
//}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _configArray.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
    static NSString *firstCellIndentifier = @"FirstLeftCellIndentifier";
    static NSString *ItemCellIndentifier = @"ItemCellIndentifier";
    

    if(indexPath.row == 0)
    {
        WZLeftFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:firstCellIndentifier];

        if(!cell)
        {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"WZLeftFirstCell" owner:nil options:nil] lastObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        cell.backgroundColor = [UIColor clearColor];

        
        return cell;
    }
    else
    {
        WZLeftItemCell *cell = [tableView dequeueReusableCellWithIdentifier:ItemCellIndentifier];

        if(!cell)
        {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"WZLeftItemCell" owner:nil options:nil] lastObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
        }
        cell.backgroundColor = [UIColor clearColor];

        [cell setDown:indexPath.row == self.currentIndex?YES:NO andConfigDictionary:_configArray[indexPath.row]];
        return cell;
    }
    

    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return indexPath.row?44:160;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [self.navMainVC popToRootViewControllerAnimated:NO];
    
    /*   row 0 为header 没有选中效果     */
    
    if(indexPath.row)
    {
        self.currentIndex = indexPath.row;
        [self.tableView reloadData];
        
    }
    switch (indexPath.row) {
        case 0:
        {


        }
            break;
        case 1:
        {

            XXCenterViewController *vv = [[XXCenterViewController alloc] init];
            self.navMainVC = [[XXNavigationController alloc] initWithRootViewController:vv];
//            [self.navMainVC pushViewController:vv animated:YES];
        }
            break;
        case 2:
        {
            XXOrderViewController *vv = [[XXOrderViewController alloc] init];
            self.navMainVC = [[XXNavigationController alloc] initWithRootViewController:vv];
            /*    提取现金     */
//            WZCashOutController *cashout = [[WZCashOutController alloc] init];
//            [self.navMainVC pushViewController:cashout animated:YES];
        }
            break;
        case 3:
        {
            /*    交易明细    */
//            WZTransactionsViewController *transactionDetail = [[WZTransactionsViewController alloc] init];
//            [self.navMainVC pushViewController:transactionDetail animated:YES];
        }
            break;
        case 4:
        {
            /*   填写邀请码     */
//            WZSetInviteViewController *invitate = [[WZSetInviteViewController alloc] init];
//            [self.navMainVC pushViewController:invitate animated:YES];
        }
            break;
        case 5:
        {
//            WZSystemViewController *sys = [[WZSystemViewController alloc] init];
//            [self.navMainVC pushViewController:sys animated:YES];
            
        }
            break;
        case 6:
        {
            /*     功能设置     */
//            WZSettingController *setting = [[WZSettingController alloc] init];
//            [self.navMainVC pushViewController:setting animated:YES];
            
        }
            break;
        case 7:
        {
            /*     客服帮助     */
//            WZAssViewController *assit = [[WZAssViewController alloc] init];
//            [self.navMainVC pushViewController:assit animated:YES];
            
        }
            break;
        default:
            break;
    }
    [self.drawerViewController setCenterViewController:self.navMainVC];

    [self closeDrawer];
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */


@end
